package com.gzhryc.shared_device.oem.code.business.dao;

import java.sql.SQLException;
import java.util.List;

import com.gzhryc.jdbc.BaseDao;
import com.gzhryc.jdbc.Conditions;
import com.gzhryc.jdbc.Query;
import com.gzhryc.shared_device.oem.code.business.dao.db.CouponActivity;

public class CouponActivityDao extends BaseDao<CouponActivity> {

    public CouponActivityDao(String jdbcKey) {
        super(jdbcKey);
    }

    public List<CouponActivity> findBySearch(Conditions conditions1, Conditions conditions2,Integer pageNo,Integer pageLimit) throws SQLException {
        Query query = new Query();

        String sql1 = "SELECT * from " + this.tableName + " t1 " + conditions1.toSql(query.getParams(),"t1",true);
        String sql2 = "SELECT * from " + this.tableName + " t2 " + conditions2.toSql(query.getParams(),"t2",true);

        String sql = "("+sql1+" ORDER BY t1.create_date)UNION ALL("+sql2+" ORDER BY t2.create_date)";
        query.setSql(sql);
        query.setPageNo(pageNo);
        query.setPageLimit(pageLimit);
        return this.jdbcHelper.find(query,CouponActivity.class);
    }
}
